home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / pp / getident.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-01  |  1.2 KB  |  48 lines

  1. /*
  2. \funcref{getident}{void getident (\params)}
  3.     {
  4.         {char} {*buf} {buffer to store identifier}
  5.     }
  6.     {}
  7.     {error()}
  8.     {lexer()}
  9.     {getident.c}
  10.     {
  11.         {\em getident()} is called from {\em lexer()} when an underscore
  12.         character or a {\em [a-zA-Z]} character is read. {\em lexer()} pushes
  13.         the character back onto the input file and calls {\em getident()} to
  14.         read an identifier.
  15.  
  16.         Identifiers are defined as starting with {\em [\_a-zA-Z]} followed by
  17.         zero or more {\em [\_a-zA-Z0-9]}.
  18.  
  19.         {\em getident()} performs no checking of the identifier length. The
  20.         buffer where the identifier is stored is assumed to be large enough to
  21.         hold the name.
  22.     }
  23. */
  24.  
  25. #include "icm-pp.h"
  26.  
  27. void getident (char *buf)
  28. {
  29.     register int
  30.         ch,
  31.         index = 0;
  32.  
  33.     if ( (ch = fgetc (filestack [filesp].f)) != '_' &&
  34.          ! isalpha (ch)
  35.        )
  36.         error ("%s: %d: identifier expected", filestack [filesp].n,
  37.                filestack [filesp].l);
  38.  
  39.     buf [index++] = ch;
  40.     while ( (ch = fgetc (filestack [filesp].f)) == '_' ||
  41.             isalnum (ch)
  42.           )
  43.             buf [index++] = ch;
  44.  
  45.     ungetc (ch, filestack [filesp].f);
  46.     buf [index] = '\0';
  47. }
  48.